/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kotionokyurievna.gmail.com.biginteger.logic;

import java.math.BigInteger;
import java.util.concurrent.atomic.AtomicReference;

/**
 *
 * @author Kateryna_Reznik
 */
public class BigNumber {
    private BigInteger value;
    private AtomicReference<BigInteger> valueRef;
       
    public BigNumber(){
        value = new BigInteger(new byte[]{1});
        valueRef = new AtomicReference<>();
        valueRef.set(value);
    }
    
    public BigInteger next(){
        value = valueRef.get();
        while (!valueRef.compareAndSet(value, value.add(value)));
        return value;
    }    
}
